package com.wanli.storemobile.homepage;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ethanhua.skeleton.Skeleton;
import com.ethanhua.skeleton.SkeletonScreen;
import com.wanli.storemobile.R;
import com.wanli.storemobile.base.BaseActivity;
import com.wanli.storemobile.base.DataCallBack;
import com.wanli.storemobile.bean.DeviceImgListBean;
import com.wanli.storemobile.homepage.adapter.DeviceImgListAdapter;
import com.wanli.storemobile.homepage.model.HomePageModelImpl;
import com.wanli.storemobile.homepage.model.IHomePageModel;
import com.wanli.storemobile.widget.AppTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class D0CodeActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.ll_no_data)
    LinearLayout llNoData;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private IHomePageModel homePageModel;
    private DeviceImgListAdapter listAdapter;
    private List<DeviceImgListBean.DataBean> beanList;
    private SkeletonScreen skeletonScreen;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_d0_code);
        ButterKnife.bind(this);
        initView();
        requestData();
    }

    private void initView() {
        homePageModel = new HomePageModelImpl();
        beanList = new ArrayList<>();
        listAdapter = new DeviceImgListAdapter(beanList);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        recyclerView.setAdapter(listAdapter);

        skeletonScreen = Skeleton.bind(recyclerView)
                .adapter(listAdapter)
                .color(R.color.shimmer_color_2)
                .shimmer(true)
                .angle(20)
                .frozen(false)
                .duration(1000)
                .count(20)
                .load(R.layout.item_skeleton_code_list)
                .show();
    }

    private void requestData() {
        homePageModel.requestDeviceImg("3", new DataCallBack<DeviceImgListBean>() {
            @Override
            public void onSuccessful(DeviceImgListBean bean) {
                beanList.addAll(bean.getData());
                listAdapter.notifyDataSetChanged();
                if (beanList.size() > 0) {
                    llNoData.setVisibility(View.GONE);
                } else {
                    llNoData.setVisibility(View.VISIBLE);
                }
                skeletonScreen.hide();
            }

            @Override
            public void onFailed(String msg, String code) {
                skeletonScreen.hide();
            }
        });
    }
}
